//
//  AdminWeb.swift
//  PerfectServer
//
//  Created by 王薰怡 on 2017/6/27.
//
//

import Foundation
import PerfectHTTP
import PerfectMustache

struct AdminWEB {
    var pageRoutes: Routes {
        var routes = Routes()
        routes.add(method: .get, uri: "/admin") { request, response in
            response.setHeader(.contentType, value: "text/html")
            mustacheRequest(
                request: request,
                response: response,
                handler: MustacheHandler(),
                templatePath: request.documentRoot + "/index.mustache"
            )
            response.completed()
        }
        routes.add(method: .get, uri: "/admin/{viewControllerName}", handler: {
            request, response in
            response.setHeader(.contentType, value: "text/html")
            if let viewControllerName = request.urlVariables["viewControllerName"], viewControllerName.characters.count > 0 {
                mustacheRequest(
                    request: request,
                    response: response,
                    handler: MustacheHandler(),
                    templatePath: request.documentRoot + "/\(viewControllerName).mustache"
                )
            } else {
                
            }
            response.completed()
        })
        return routes
    }
    
    static func redirect(to viewControllerName: String) {
    
    }

}
